﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

///This class will be the Interim for the menu navigation.
///
enum State//each screen will contain their own one of these, as well as a get-set function to pass to each other screen.
{
    Active = 1,
    Hidden = 2,
    Loading = 3,
    Kill = 4,//this may be used for deletion. Just a forethought.
} 

namespace MyImaginaryFriends_Redux
{
    class ScreenHandler
    {
        #region variables



        #endregion

        #region Classes

        private ContentManager cm_GrabContent;//for loading gameplay screen content on the go.

        Screens.MainMenu TitleScreen;
        Screens.TitleOptionsMenu OptionsScreen;
        Screens.GameplayScreen GameScreen;

        #endregion

        //Construct and initialize in one.
        public ScreenHandler()
        {
            TitleScreen = new Screens.MainMenu();
            OptionsScreen = new Screens.TitleOptionsMenu();
            GameScreen = new Screens.GameplayScreen();
        }


        public void LoadContent(ContentManager content)
        {
            cm_GrabContent = content;

            TitleScreen.LoadContent(content);
            OptionsScreen.LoadContent(content);
           
        }

        public void Update(ContentManager content, GameTime gameTime, InputHandler input)//input is here as a passthrough.
        {
           
            TitleScreen.Update(gameTime, input, OptionsScreen,GameScreen);
            OptionsScreen.Update(gameTime, input, TitleScreen, GameScreen);

            GameScreen.LoadContent(cm_GrabContent, TitleScreen, OptionsScreen);

            GameScreen.Update(content, gameTime, input, TitleScreen, OptionsScreen);

            if (GameScreen.ReinitializeCommand)
            {
                GameScreen.DeathScreenActive = false;
                GameScreen.SetGamePlayScreenState(State.Hidden);
                Reinitialize(content);
            }
        }

        public void Reinitialize(ContentManager content)
        {
            TitleScreen = new Screens.MainMenu();
            OptionsScreen = new Screens.TitleOptionsMenu();
            GameScreen = new Screens.GameplayScreen();

            LoadContent(content);
            
        }

        public bool GetTitleScreenExitCmd()
        {
            return TitleScreen.PassExitCommand();
        }

        public bool GetGameScreenExitCommand()
        {
            return GameScreen.PassExitCommand();
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            TitleScreen.Draw(spriteBatch, OptionsScreen);
            OptionsScreen.Draw(spriteBatch, TitleScreen);

            GameScreen.Draw(spriteBatch);
        }

    }
}
